<?php

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Repository\RepositoryInterface\UserLoginInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

//前台用户注册类
class UserLoginController extends Controller
{
    //
    protected $userLogin;

    public function __construct(UserLoginInterface $userLogin){
        return $this->userLogin = $userLogin;
    }

    /**
     * @param Request $request
     * 发送验证码
     */
    public function sendCode(Request $request){
        $phone=$request->get('phone');
        return $this->userLogin->sendCode($phone);
    }

    /**
     * @param Request $request
     * 用户注册方法
     */
    public function register(Request $request){
        $register_data=$request->except('Invitationcode');
        return $this->userLogin->userRegister($register_data);
    }

    /**
     * @param Request $request
     * 校验用户登录的账号密码方法
     */
    public function verify(Request $request){
        $data=$request->post();
        return $this->userLogin->verify($data);
    }

    /**
     * @param Request $request
     * 修改用户信息
     */
    public function upUserInfo(Request $request){
        $user_data=$request->except('jwtToken');
        return $this->userLogin->upUserInfo($user_data,$request->id);
    }

    /**
     * @param Request $request
     * 查询修改用户信息
     */
    public function findUser(Request $request){
        return $this->userLogin->findUser($request->id);
    }

    /**
     * @param Request $request
     * 用户修改头像
     */
    public function changeAvatar(Request $request){
        $avatar=$request->file('image');
        return $this->userLogin->changeAvatar($avatar,$request->id);
    }

    /**
     * @param Request $request
     * @return mixed
     * 查询当前用户信息
     */
    public function findUserData(Request $request){
        $uid = $request->post("uid");
        $userData = $this->userLogin->findUserData($uid);
        return $userData;
    }

    /**
     * @param Request $request
     * @return mixed
     * 人脸识别方法
     */
    public function face(Request $request){
        $file=$request->file('file');
        return $this->userLogin->face($file,$request->id);
    }
}
